﻿using System;
using System.Text;

namespace OmniKits.Extensions
{
    using NullGuard;

    public static class UriExtensions
    {
        public static Uri ToProgrammingFriendlyUri([AllowNull]this Uri source)
        {
            if (source == null)
                return source;

            if (!source.IsAbsoluteUri || !source.Authority.IsNullOrEmpty())
                return source;

            switch (source.AbsolutePath[0])
            {
                case '.':
                case '/':
                    return source;
            }

            return new Uri(source.Scheme + "://" + source.AbsolutePath);
        }
    }
}
